package com.tfswue.lhj.common;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * 分页查询参数
 * 
 * @author daygods
 * @since 2025-07-07
 */
public class PageQuery {
    
    /**
     * 当前页码
     */
    @Min(value = 1, message = "页码不能小于1")
    private Integer current = 1;
    
    /**
     * 每页大小
     */
    @Min(value = 1, message = "每页大小不能小于1")
    @Max(value = 100, message = "每页大小不能超过100")
    private Integer size = 10;
    
    /**
     * 排序字段
     */
    private String sortField;
    
    /**
     * 排序方向 asc/desc
     */
    private String sortOrder = "desc";
    
    /**
     * 搜索关键词
     */
    private String keyword;
    
    public PageQuery() {}
    
    public PageQuery(Integer current, Integer size) {
        this.current = current;
        this.size = size;
    }
    
    public PageQuery(Integer current, Integer size, String sortField, String sortOrder) {
        this.current = current;
        this.size = size;
        this.sortField = sortField;
        this.sortOrder = sortOrder;
    }
    
    /**
     * 获取偏移量
     */
    public Integer getOffset() {
        return (current - 1) * size;
    }
    
    /**
     * 是否升序
     */
    public boolean isAsc() {
        return "asc".equalsIgnoreCase(sortOrder);
    }
    
    // Getters and Setters
    public Integer getCurrent() {
        return current;
    }
    
    public void setCurrent(Integer current) {
        this.current = current;
    }
    
    public Integer getSize() {
        return size;
    }
    
    public void setSize(Integer size) {
        this.size = size;
    }
    
    public String getSortField() {
        return sortField;
    }
    
    public void setSortField(String sortField) {
        this.sortField = sortField;
    }
    
    public String getSortOrder() {
        return sortOrder;
    }
    
    public void setSortOrder(String sortOrder) {
        this.sortOrder = sortOrder;
    }
    
    public String getKeyword() {
        return keyword;
    }
    
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
}